package net.maku.system.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor;
import net.maku.framework.common.utils.PageResult;
import net.maku.framework.mybatis.service.impl.BaseServiceImpl;
import net.maku.system.convert.SysUserWalletConvert;
import net.maku.system.entity.SysUserWalletEntity;
import net.maku.system.query.SysUserWalletQuery;
import net.maku.system.vo.SysUserWalletVO;
import net.maku.system.dao.SysUserWalletDao;
import net.maku.system.service.SysUserWalletService;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 购买订单管理
 *
 * @author 小陈 www.hong.ch@qq.com
 * @since 1.0.0 2025-03-24
 */
@Service
@AllArgsConstructor
public class SysUserWalletServiceImpl extends BaseServiceImpl<SysUserWalletDao, SysUserWalletEntity> implements SysUserWalletService {

    @Override
    public PageResult<SysUserWalletVO> page(SysUserWalletQuery query) {
        IPage<SysUserWalletEntity> page = baseMapper.selectPage(getPage(query), getWrapper(query));

        return new PageResult<>(SysUserWalletConvert.INSTANCE.convertList(page.getRecords()), page.getTotal());
    }

    private LambdaQueryWrapper<SysUserWalletEntity> getWrapper(SysUserWalletQuery query){
        LambdaQueryWrapper<SysUserWalletEntity> wrapper = Wrappers.lambdaQuery();
        return wrapper;
    }

    @Override
    public void save(SysUserWalletVO vo) {
        SysUserWalletEntity entity = SysUserWalletConvert.INSTANCE.convert(vo);

        baseMapper.insert(entity);
    }

    @Override
    public void update(SysUserWalletVO vo) {
        SysUserWalletEntity entity = SysUserWalletConvert.INSTANCE.convert(vo);

        updateById(entity);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delete(List<Long> idList) {
        removeByIds(idList);
    }

}